package xyz.liut.ee.resp

import jakarta.servlet.http.HttpServletResponse
import xyz.liut.ee.web.gson
import xyz.liut.logcat.kt.logDebug
import java.io.IOException

/**
 * 发送响应
 *
 * @param resp   HttpServletResponse
 */
@Throws(IOException::class)
fun ResponseEntity<*>?.sendBy(resp: HttpServletResponse) {
    resp.contentType = "application/json;charset=UTF-8"
    resp.characterEncoding = "UTF-8"
    resp.status = 200
    val msg: String = gson.toJson(this ?: ResponseEntity<Any>())
    resp.writer.println(msg)
    logDebug { msg }
}
